#ifndef SDK_GLOBALS_H
#define SDK_GLOBALS_H

#include <vector>
#include <wx/string.h>
#include <wx/treectrl.h>
#include <wx/file.h>
#include <wx/filename.h>
#include <wx/intl.h>
#include <wx/msgdlg.h>
#include <wx/bitmap.h>

#define HL_AUTO _T(" ")
#define HL_NONE _T("  ")

typedef wxString HighlightLanguage;
typedef std::vector<wxString> wxStringVec;

class TiXmlDocument;
class wxListCtrl;
class wxWindow;

class cbProjectTreeImages {
  public:
    static wxImageList* MakeImageList();
    static int WorkspaceIconIndex( bool read_only = false );
    static int ProjectIconIndex( bool read_only = false );
    static int FolderIconIndex();
    static int VirtualFolderIconIndex();
};

enum PluginType {
  ptNone = 1,
  ptTool,
  ptMime,
  ptCompiler,
  ptDebugger,
  ptCodeCompletion,
  ptWizard,
  ptSmartIndent,
  ptOther
};

enum FileType {
  ftm_Code_Project = 0,
  ftm_Code_Workspace,
  ftShell,
  ftLua,
  ftText,
  ftHtml,
  ftPhp,
  ftAsp,
  ftCss,
  ftConf,
  ftSource,
  ftHeader,
  ftTemplateSource,
  ftObject,
  ftXRCResource,
  ftResource,
  ftResourceBin,
  ftStaticLib,
  ftDynamicLib,
  ftExecutable,
  ftNative,
  ftXMLDocument,
  ftScript,
  ftOther
};

enum ModuleType {
  mtProjectManager = 1,
  mtEditorManager,
  mtLogManager,
  mtOpenFilesList,
  mtEditorTab,
  mtUnknown
};

enum FileVisualState {
  fvsNormal = 0,
  fvsMissing,
  fvsModified,
  fvsReadOnly,
  fvsVcAdded,
  fvsVcConflict,
  fvsVcMissing,
  fvsVcModified,
  fvsVcOutOfDate,
  fvsVcUpToDate,
  fvsVcRequiresLock,
  fvsVcExternal,
  fvsVcGotLock,
  fvsVcLockStolen,
  fvsVcMismatch,
  fvsVcNonControlled,
  fvsWorkspace,
  fvsWorkspaceReadOnly,
  fvsProject,
  fvsProjectReadOnly,
  fvsFolder,
  fvsVirtualFolder,
  fvsLast
};

enum DirAccessCheck {
  dacInvalidDir,
  dacReadWrite,
  dacReadOnly
};

enum SettingsIconsStyle {
  sisLargeIcons = 0,
  sisNoIcons = 1
};

enum cbPlaceDialogMode {
  pdlDont = 0, pdlBest, pdlCentre, pdlHead, pdlConstrain, pdlClip
};

enum ProjectTreeVisualState {
  ptvsNone = 0x00,
  ptvsCategorize = 0x01,
  ptvsUseFolders = 0x02,
  ptvsHideFolderName = 0x04,
  ptvsDefault = 0x03
};

enum TemplateOutputType {
  totProject = 0,
  totTarget,
  totFiles,
  totCustom,
  totUser
};

enum SupportedPlatforms {
  spMac = 0x01,
  spUnix = 0x02,
  spWindows = 0x04,
  spAll = 0xff
};

extern const wxString DEFAULT_WORKSPACE;
extern const wxString DEFAULT_ARRAY_SEP;
extern const wxString DEFAULT_CONSOLE_TERM;
extern const wxString DEFAULT_CONSOLE_SHELL;
extern const wxString cbDEFAULT_OPEN_FOLDER_CMD;
extern bool cbRead( wxFile& file, wxString& st, wxFontEncoding encoding = wxFONTENCODING_SYSTEM );
extern wxString cbReadFileContents( wxFile& file, wxFontEncoding encoding = wxFONTENCODING_SYSTEM );
extern bool cbWrite( wxFile& file, const wxString& buff, wxFontEncoding encoding = wxFONTENCODING_SYSTEM );
extern bool cbSaveToFile( const wxString& filename, const wxString& contents, wxFontEncoding encoding = wxFONTENCODING_SYSTEM, bool bom = false );
extern bool cbSaveTinyXMLDocument( TiXmlDocument* doc, const wxString& filename );
extern wxString cbC2U( const char* str );
extern const wxWX2MBbuf cbU2C( const wxString& str );
extern wxFontEncoding DetectEncodingAndConvert( const char* strIn, wxString& strOut, wxFontEncoding possibleEncoding = wxFONTENCODING_SYSTEM );
extern wxString GetStringFromArray( const wxArrayString& array, const wxString& separator = DEFAULT_ARRAY_SEP, bool SeparatorAtEnd = true );
extern wxArrayString GetArrayFromString( const wxString& text, const wxString& separator = DEFAULT_ARRAY_SEP, bool trimSpaces = true );
extern wxStringVec GetVectorFromString( const wxString& text, const wxString& separator = DEFAULT_ARRAY_SEP, bool trimSpaces = true );
extern wxArrayString MakeUniqueArray( const wxArrayString& array, bool caseSens );
extern wxString MakeUniqueString( const wxString& text,  const wxString& separator = DEFAULT_ARRAY_SEP, bool caseSens = true );
extern void AppendArray( const wxArrayString& from, wxArrayString& to );
extern wxString UnixFilename( const wxString& filename, wxPathFormat format = wxPATH_NATIVE );
extern void QuoteStringIfNeeded( wxString& str );
extern bool NeedQuotes( const wxString &str );
extern wxString EscapeSpaces( const wxString& str );
extern FileType FileTypeOf( const wxString& filename );
extern wxString cbFindFileInPATH( const wxString &filename );
extern void SaveTreeState( wxTreeCtrl* tree, const wxTreeItemId& parent, wxArrayString& nodePaths, wxArrayString& selectedItemPaths );
extern void RestoreTreeState( wxTreeCtrl* tree, const wxTreeItemId& parent, wxArrayString& nodePaths, wxArrayString& selectedItemPaths );
extern bool CreateDirRecursively( const wxString& full_path, int perms = 0755 );
extern bool CreateDir( const wxString& full_path, int perms = 0755 );
extern wxString ChooseDirectory( wxWindow* parent, const wxString& message = _T( "Select directory" ), const wxString& initialPath = _T( "" ), const wxString& basePath = _T( "" ),
                                 bool askToMakeRelative = false, bool showCreateDirButton = false );
extern bool NormalizePath( wxFileName& f, const wxString& base );
extern bool IsSuffixOfPath( wxFileName const & suffix, wxFileName const & path );
extern bool cbResolveSymLinkedDirPath( wxString& dirpath );
extern wxString cbResolveSymLinkedDirPathRecursive( wxString dirpath );
extern wxString URLEncode( const wxString &str );
extern wxString ExpandBackticks( wxString &str );
extern wxMenu* CopyMenu( wxMenu* mnu, bool with_accelerators = false );
extern bool UsesCommonControls6();
extern wxBitmap M_Code_LoadBitmap( const wxString& filename, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG );
extern bool IsWindowReallyShown( wxWindow* win );
extern void SetSettingsIconsStyle( wxListCtrl* lc, SettingsIconsStyle style );
extern SettingsIconsStyle GetSettingsIconsStyle( wxListCtrl* lc );
extern SettingsIconsStyle GetSettingsIconsStyle();
extern void PlaceWindow( wxTopLevelWindow *w, cbPlaceDialogMode mode = pdlBest, bool enforce = false );
extern int msging( const wxString& message, const wxString& caption = wxEmptyString, int style = wxOK, wxWindow *parent = NULL, int x = -1, int y = -1 );
extern int cbGetSingleChoiceIndex( const wxString& message, const wxString& caption, const wxArrayString& choices, wxWindow *parent = NULL, const wxSize &size = wxSize( 300, 300 ),
                                   int initialSelection = 0 );
extern wxArrayInt cbGetMultiChoiceDialog( const wxString& message, const wxString& caption,
    const wxArrayString& choices, wxWindow *parent = nullptr,
    const wxSize& size = wxSize( 300, 300 ),
    const wxArrayInt& initialSelection = wxArrayInt() );
extern const wxChar *cbGetTextFromUserPromptStr;
extern wxString cbGetTextFromUser( const wxString &message, const wxString &caption = cbGetTextFromUserPromptStr,
                                   const wxString &default_value = wxEmptyString, wxWindow *parent = NULL,
                                   int x = wxDefaultCoord, int y = wxDefaultCoord, bool centre = true );
extern DirAccessCheck cbDirAccessCheck( const wxString& dir );
extern wxString realpath( const wxString& path );

inline void NotifyMissingFile( const wxString &name ) {
  wxString msg;
  msg.Printf( _T( "文件 %s 以丢失" ), name.c_str() );
  msging( msg );
}

#endif
